package com.gitee.wsl.struct.table.mini.dsl

import com.gitee.wsl.struct.table.mini.Row

@PicnicDsl
interface RowDsl {
    fun cell(content: Any?, style: CellDsl.() -> Unit = {})

    fun cells(vararg content: Any?, style: CellDsl.() -> Unit = {}) {
        content.forEach { cell(it, style) }
    }

    fun cellStyle(content: CellStyleDsl.() -> Unit)
}


internal class RowDslImpl : RowDsl {
    private val builder = Row.Builder()
    private val cellStyleImpl = CellStyleDslImpl()

    override fun cell(content: Any?, style: CellDsl.() -> Unit) {
        builder.addCell(CellDslImpl(content).apply(style).create())
    }

    override fun cellStyle(content: CellStyleDsl.() -> Unit) {
        cellStyleImpl.apply(content)
    }

    fun create() = builder.setCellStyle(cellStyleImpl.createOrNull()).build()
}